import { Button, Modal } from 'antd';
import React, { useState } from 'react';
import '../../../assets/css/Car/Addcar.css';
import axios from '../../../utils/axios'
const Addcar = () => {
  const [visible, setVisible] = useState(false);

  // 申明数据对象
  const mycarvaluearr = {
    car_location: '',
    car_Status: '',
    car_model: '',
    car_color: '',
    car_id: '',
  }
  // 获取输入值
  const getcarvalue = (e) => {
    console.log(e.target.name + e.target.value);
    // console.log(mycarvaluearr);
    mycarvaluearr[e.target.name] = e.target.value;
  }
  const Addcarfas = () => {
    setVisible(false)
    console.log('发送请求了')
    axios({
      url: "/car/carPage/saveCar",
      method: "get",
      params: {
        car_location: mycarvaluearr.car_location,
        car_Status: mycarvaluearr.car_Status,
        car_model: mycarvaluearr.car_model,
        car_color: mycarvaluearr.car_color,
        car_id: mycarvaluearr.car_id

      }
    }).then((res) => {
      console.log(res);
    }).then((err) => {
      console.log(err);
    })
  }
  return (
    <>
      <Button type="primary" onClick={() => setVisible(true)} className='addbtn'>
        新增车辆
      </Button>
      <Modal
        title="新增车辆"
        centered
        visible={visible}
        okText={'确认'}
        cancelText={'取消'}
        onOk={Addcarfas }
        onCancel={() => setVisible(false)}
        width={500}
        destroyOnClose
      
      >

        <form>
          <div className='ibox'>
            <span className='xh'>* </span><span>所在位置：</span>
            <select onChange={getcarvalue} name='car_location'>
              <option name='0'>请选择</option>
              <option name='总经办'>总经办</option>
              <option name='财务部'>财务部</option>
              <option name='业务一部'>业务一部</option>
              <option name='业务二部'>业务二部</option>
              <option name='渠道招商'>渠道招商部</option>
              <option name='营销部'>营销部</option>
              <option name='采购部'>采购部</option>
              <option name='客服部'>客服部</option>
            </select>
          </div>

          <div className='ibox'>
            <span className='xh'>* </span><span>车辆状态：</span>
            <select onChange={getcarvalue} name='car_Status'>
              <option name='0'>请选择</option>
              <option name='使用中'>使用中</option>
              <option name='闲置'>闲置</option>
            </select>
          </div>

          <div className='ibox'>
            <span className='xh'>* </span>
            <span>车辆型号：</span>
            <input type="text" onChange={getcarvalue} name='car_model' ></input>
          </div>
          <div className='ibox'>
            <span className='xh'>* </span>
            <span>车辆颜色：</span>
            <input type="text" onChange={getcarvalue} name='car_color' ></input>
          </div>

          <div className='ibox'>
            <span className='xh'>* </span>
            <span>车辆牌照：</span>
            <input type="text" onChange={getcarvalue} name='car_id' ></input>
          </div>

        </form>
      </Modal>
    </>
  );
};

export default Addcar;
